package com.utils.conmponentbase.base.viewpager2;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * MvvmDemo com.utils.conmponentbase.base.viewpager2
 * 2020-01-07 13:17
 */
public class BaseViewPager2Adapter extends FragmentStateAdapter {
    private List<Fragment> mFragments = new ArrayList<>();

    public BaseViewPager2Adapter(@NonNull FragmentActivity fragmentActivity, List<Fragment> pFragments) {
        super(fragmentActivity);
        mFragments = pFragments;
    }

    public BaseViewPager2Adapter(@NonNull Fragment fragment, List<Fragment> pFragments) {
        super(fragment);
        mFragments = pFragments;
    }

    public BaseViewPager2Adapter(@NonNull FragmentManager fragmentManager, @NonNull Lifecycle lifecycle, List<Fragment> pFragments) {
        super(fragmentManager, lifecycle);
        mFragments = pFragments;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getItemCount() {
        return mFragments.size();
    }
}
